// 数据源
import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex);//vue的插件机制

//Vuex.Store 构造器选项
const store = new Vuex.Store({
    state:{//存放状态
        "new_colum": 8 ,// 当前行数
		"new_model": "8x8", // 当前模式
		"timeId": "", // index页面计时器id
		"bombNumber": 10, // 炸弹数量
		"userStatus": "离线", // 是否登录标识
		"opponet":null, // 挑战对手信息
		"pkInfo": null, // pk信息
		"msgList": [] ,//消息列表
		"timeTask": null,
		"start_timeId": null ,// 心跳任务
		"opponetTimeId": null // 监听对手状态任务
    },
	mutations: {
		setOpponetTime(state,id){
			state.opponetTimeId = id
		},
		setStartTimeId(state,id){
			state.start_timeId = id
		},
		setUserStatus(state,status){
			state.userStatus = status
		},
		setCurrentPage(state,page) {
			state.currentPage = page 
		},
		setTimeTask(state,tid){
			state.timeTask = tid 
		},
		setMsgList(state,list){
			state.msgList = list 
		},
		addMsgList(state,list){
			state.msgList.push(list)
		},
		removeMsgList(state,id){
			for (var i = 0; i < state.msgList.length; i++) {
				if(state.msgList[i].opponetInfo.id == id){
					state.msgList.splice(i,1)
				}
			}
		},
		setPkInfo(state,info){
			state.pkInfo = info
		},
		setOpponet(state,info){
			state.opponet = info
		},
		clearTimeId(state,id){
			clearInterval(state.timeId)
			state.timeId = ""
		},
		setTimeId(state, id){
			state.timeId = id
		},
		setBombNumber(state,num){
			state.bombNumber = num
		},
		// 修改行数
		setColum(state, colum){
			state.new_colum = colum
			state.new_model = colum+"x"+colum
		},
		// 初始化
		init(state){
			state.new_colum = 0
		}
	}
})
export default store